Imports System.Windows.Forms
Imports DemosCommonCode.Pdf.Security
Imports Vintasoft.Pdf
Imports Vintasoft.Pdf.Security

Namespace Pdf
	Public Partial Class SelectPdfFormatForm
		Inherits Form

		#Region "Constructor"

		Public Sub New(initalFormat As PdfFormat, initalEncryptionSettings As EncryptionSystem)
			InitializeComponent()
			formatComboBox.SelectedIndex = 0
			_format = initalFormat
			pdfVersion.SelectedItem = _format.Version
			compressedCrossReferenceTable.Checked = _format.CompresedCrossReferenceTable
			binaryFormat.Checked = _format.BinaryFormat
			_newEncryptionSettings = initalEncryptionSettings
		End Sub

		#End Region


		#Region "Properties"

		Private _format As PdfFormat
		Public ReadOnly Property Format() As PdfFormat
			Get
				Select Case formatComboBox.SelectedIndex
					Case 0
						Return _format
					Case 1
						Return PdfFormat.Pdf_A
				End Select
				Return Nothing
			End Get
		End Property

		Private _newEncryptionSettings As EncryptionSystem
		Public ReadOnly Property NewEncryptionSettings() As EncryptionSystem
			Get
				Return _newEncryptionSettings
			End Get
		End Property

		#End Region


		#Region "Methods"

		Private Sub buttonOk_Click(sender As Object, e As EventArgs)
			Select Case formatComboBox.SelectedIndex
				Case 0
					_format = New PdfFormat(pdfVersion.SelectedItem.ToString(), compressedCrossReferenceTable.Checked, binaryFormat.Checked)
					Exit Select
				Case 1
					'PDF/A
					_format = PdfFormat.Pdf_A
					Exit Select
			End Select
			DialogResult = System.Windows.Forms.DialogResult.OK
			Close()
		End Sub

		Private Sub buttonCancel_Click(sender As Object, e As EventArgs)
			DialogResult = System.Windows.Forms.DialogResult.Cancel
			Close()
		End Sub

		Private Sub formatComboBox_SelectedIndexChanged(sender As Object, e As EventArgs)
			panel1.Visible = formatComboBox.SelectedIndex = 0
		End Sub

		Private Sub pdfVersion_SelectedIndexChanged(sender As Object, e As EventArgs)
			securityButton.Enabled = pdfVersion.SelectedIndex >= 1
			If pdfVersion.SelectedIndex > 4 Then
				compressedCrossReferenceTable.Checked = _format.CompresedCrossReferenceTable
				compressedCrossReferenceTable.Enabled = True
			Else
				compressedCrossReferenceTable.Checked = False
				compressedCrossReferenceTable.Enabled = False
			End If
		End Sub

		Private Sub securityButton_Click(sender As Object, e As EventArgs)
			Dim securitySettings As New SecuritySettingsForm(_newEncryptionSettings)
			If securitySettings.ShowDialog() = DialogResult.OK Then
				_newEncryptionSettings = securitySettings.NewEncryptionSettings
			End If
		End Sub

		#End Region


	End Class
End Namespace
